import { createSSRApp } from 'vue'
import { createPinia } from 'pinia'

import { createPersistedState } from 'pinia-plugin-persistedstate'

// 数据持久化

import App from './App.vue'

import 'uno.css'
import http from './utils/http'

import { getSiteInfo } from './utils/common.js'
import uviewPlus from '@/uni_modules/uview-plus'
import mixins from '~/utils/mixins'

export function createApp() {
  const app = createSSRApp(App)
  const siteinfo: any = getSiteInfo()
  app.config.globalProperties.$siteinfo = siteinfo
  // 设置请求地址
  http.setHost(siteinfo.baseUrl)
  // 挂载http请求
  app.config.globalProperties.$http = http
  app.use(uviewPlus)
  app.mixin(mixins)
  const pinia = createPinia()
  pinia.use(
    createPersistedState({
      storage: {
        getItem: uni.getStorageSync,
        setItem: uni.setStorageSync,
      },
    }),
  )
  app.use(pinia)
  return {
    app,
  }
}
